﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace popoBCadd_in
{
    class ECB
    {
        //Pada mode ECB, blok plainteks yang sama selalu dienkripsi menjadi blok cipherteks yang sama. 
        public static byte[] encrypt(byte[] plain, byte[] key)
        {
            int blocklength = key.Length;

            int totalblock = plain.Length / blocklength;

            byte[] cipher = new byte[plain.Length];

            for (int i = 0; i < totalblock; i++)
            {
                byte[] currentblock = generateTrueKey.getNbyteKey(plain, i * blocklength, blocklength);
                byte[] currentcipher = feistel.feistelencrypt(currentblock, key);
                currentcipher.CopyTo(cipher, i * blocklength);
            }

            return cipher;
        }

        public static byte[] decrypt(byte[] cipher, byte[] key)
        {
            int blocklength = key.Length;
            int totalblock = cipher.Length / blocklength;

            byte[] plain = new byte[cipher.Length];
            for (int i = 0; i < totalblock; i++)
            {
                byte[] currentblock = generateTrueKey.getNbyteKey(cipher, i * blocklength, blocklength);
                byte[] currentplain = feistel.feisteldecrypt(currentblock, key);
                currentplain.CopyTo(plain, i * blocklength);
            }

            return plain;
        }
    }
}
